<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>表单</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/static/plugins/font-awesome/css/font-awesome.min.css">
                <script type="text/javascript" charset="utf-8" src="/writes/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="/writes/ueditor.all.js"> </script>
		<script src="/static/js/inout/jquery-1.8.2.min.js"></script>
                
	</head>

	<body>
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
				<legend>手册内容</legend>
			</fieldset>

			<form class="layui-form">
                            <input type="hidden" value="{$find.id}" name="id" id="id" />
				<div class="layui-form-item">
					<label class="layui-form-label">标题</label>
					<div class="layui-input-block">
						<input type="text" name="title" id="title" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input" value="{$find.title}">
					</div>
				</div>
                                <style>
                                    .layui-form-selected dl{
                                        z-index: 1000;
                                    }
                                </style>
				<div class="layui-form-item">
					<label class="layui-form-label">分类</label>
					<div class="layui-input-inline">
                                                <div class="layui-input-inline">
                                                        <select name="group" id="group" lay-verify="" lay-search>
                                                            <option value="">请选择</option>
                                                            {volist name='data' id='dt'}
                                                            <optgroup label="{$dt.title}">
                                                                {volist name='dt.child' id='cdt'}
                                                                    <option value="{$cdt.id}" {eq name='find.group' value='$cdt["id"]'}selected{/eq}>{$cdt.title}</option>
                                                                {/volist}
                                                            </optgroup>
                                                            {/volist}
                                                        </select>
                                                </div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">排序</label>
						<div class="layui-input-inline">
							<input type="number" name="sort" id="sort" lay-verify="number" autocomplete="off" class="layui-input" value="{$find.sort}">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-block">
						<input type="checkbox" lay-skin="switch" title="状态" lay-text="启用|禁用" lay-filter="isShow" {eq name='find.status' value='1'}checked{/eq}>
                                                <input type="hidden" name="status" id="status" value="{$find.status}"/>
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">编辑器</label>
					<div class="layui-input-block">
                                            <script id="editor" type="text/plain" style="width:100%;height:300px;">{php}echo html_entity_decode($find['contents'],ENT_QUOTES);{/php}</script>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="addNews">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
		<script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
		<script>
                     
                        var DataDeal = {
                            //将从form中通过$('#form').serialize()获取的值转成json
                                formToJson: function (data) {
                                    data=data.replace(/&/g,"\",\"");
                                    data=data.replace(/=/g,"\":\"");
                                    data="{\""+data+"\"}";
                                    return data;
                                 },
                            };
			layui.use(['form', 'layedit', 'laydate','jquery'], function() {
				var form = layui.form(),
				layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;
                                         $ = layui.jquery;
                                        UE.getEditor('editor');
//				//创建一个编辑器
//                                layedit.set({
//                                    uploadImage: {
//                                      url: '{:url("adminmanual/ajaxUpload")}' //接口url
//                                      ,type: 'post' //默认post
//                                    }
//                                  });
				var editIndex = layedit.build('edit');
                                
                                 form.on('switch(isShow)', function(data){
                                        var status=1;
                                        $(this).is(":checked")?status=1:status=2;
                                        $('#status').val(status);
                                  })
                                form.on("submit(addNews)",function(data){
                                        //弹出loading
                                        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
                                        $.ajax({
                                            type: "POST",
                                            url: "{:url('adminmanual/saveData')}",
                                            data: {title:$('#title').val(),sort:$('#sort').val(),status:$('#status').val(),group:$('#group').val(),contents:UE.getEditor('editor').getContent(),id:$('#id').val()},
                                            dataType: "json",
                                            success: function(data){
                                                top.layer.close(index);
                                                if(data.status == 0){
                                                  $('#sear', window.parent.document).click();
                                                  top.layer.msg(data.msg,{icon: 6});
                                                  parent.layer.closeAll()
                                                }else{
                                                    top.layer.msg(data.msg,{icon: 5,btn: ['知道了']});
                                                }
                                            }
                                        });
                                        return false;
                                })
			});
                        
                       
		</script>
	</body>

</html>